package com.opennetexam.manager.config;

import com.opennetexam.manager.utils.ExamSitePath;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;


/**
 * @author 奶茶
 * Created on 2017/11/19.
 */
public class MvcConfig extends WebMvcConfigurerAdapter{

    /**
     * 配置默认首页
     * @param registry
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry){
        registry.addViewController("/").setViewName("forward:/Login/Index");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
        super.addViewControllers(registry);
    }

    /**
     * 配置访问静态资源
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){
        String pathStr = ExamSitePath.rootPath + "/";
        registry.addResourceHandler("/images/**").addResourceLocations("file:" + pathStr);
        super.addResourceHandlers(registry);
    }

}
